##############################################################################
# Filename: Analysis_ArticleEvaluation_behavioral.R
# Purpose: Produce Table 3 in main text 
##############################################################################

source("Setup.R")

### Table 3: Effect of article read and level of BJP support on 
          #  time and effort spent completing tasks
## Time spent 
# Time spent on article + evaluation pages (Column 1)
p95_all <- quantile(data_eval$Time_Article_All, 0.95)
p05_all <- quantile(data_eval$Time_Article_All, 0.05)
data_eval_2 = data_eval[which(data_eval$Time_Article_All <= p95_all & data_eval$Time_Article_All >= p05_all), ]
data_eval_2 %>% group_by(Article_Alignment) %>% summarise(mean(Time_Article_All))
mod_time_articletotal_main = lm(Time_Article_All ~ ProBJP*Article + CollegeGrad + NewsDaily + StrongInterestPolitics, data = data_eval_2) 
# Time spent on article page (Column 2)
p95_page <- quantile(data_eval$Time_Article_Page, 0.95)
p05_page <- quantile(data_eval$Time_Article_Page, 0.05)
data_eval_2 = data_eval[which(data_eval$Time_Article_Page<= p95_page & data_eval$Time_Article_Page >= p05_page), ]
mod_time_articlepage_main = lm(Time_Article_Page ~ ProBJP*Article + CollegeGrad + NewsDaily + StrongInterestPolitics, data = data_eval_2) 
rm(p95_all, p05_all, p95_page, p05_page, data_eval_2)

## Words written (Column 3)
data_eval %>% group_by(Article_Alignment) %>% summarise(mean(wordcount))
mod_words_everyone_main = lm(wordcount ~ ProBJP*Article + CollegeGrad + NewsDaily + StrongInterestPolitics, data = data_eval) 

## Clicks (Column 4)
mod_clicks_main = lm(Clicks_Article_Page ~ ProBJP*Article + CollegeGrad + NewsDaily + StrongInterestPolitics, data = data_eval)

## Print
stargazer(mod_time_articletotal_main, mod_time_articlepage_main, mod_words_everyone_main, mod_clicks_main,
          align=TRUE, keep.stat="n", no.space=TRUE,
          se = starprep(mod_time_articletotal_main, mod_time_articlepage_main, mod_words_everyone_main, mod_clicks_main),
          covariate.labels=c("Pro-BJP","Positive Article",
                             "College Graduate", "Daily News", "Interested in Politics",
                             "Pro-BJP x Positive Article"))

rm(mod_time_articletotal_main, mod_time_articlepage_main, mod_words_everyone_main, mod_clicks_main)
